Skip to content

Fix fmod post-condition check for negative remainders - #771

Merged
ckormanyos merged 1 commit into
boostorg:developfrom
0x74h51N:git_issue_764
Aug 24, 2026
Merged

Fix fmod post-condition check for negative remainders#771
ckormanyos merged 1 commit into
boostorg:developfrom
0x74h51N:git_issue_764

Conversation

@0x74h51N

@0x74h51N 0x74h51N commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #764

The post-condition added in #605 tests |r| >= |b|, but does it with a signed compare against an operand matched to the remainder's sign. That equivalence only holds while both values are positive; once the remainder is negative the ordering reverses and every valid remainder satisfies it, so the correction fires on every call and adds one |b|. What comes back is the Euclidean remainder instead of the truncated one.

The comparison is now read by magnitude. The branch structure and the subtraction directions are unchanged.

git_issue_604.cpp covered all four sign combinations, but only with a zero remainder, where both conventions agree, so it could not separate them. It now also covers non-zero remainders and |a| < |b|.

This keeps fmod on std::fmod semantics, which is what float128 and mpfr_float still return.

  The check compared signed values instead of magnitudes, so it fired on every
  negative remainder, git_issue_604.cpp now covers non-zero remainders too
@ckormanyos

Copy link
Copy Markdown
Member

Hi @0x74h51N I just approved your workflow run. In this repo first-time contributors need workflow approval run. I see you also added relevant tests to this issue resolution. Thank you for those as well.

Let's see how CI runs.

@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.2%. Comparing base (14ba272) to head (16b57d0).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           develop    #771     +/-   ##
=========================================
+ Coverage     96.2%   96.2%   +0.1%     
=========================================
  Files          302     302             
  Lines        29478   29512     +34     
=========================================
+ Hits         28344   28378     +34     
  Misses        1134    1134             
Files with missing lines Coverage Δ
...nclude/boost/multiprecision/detail/default_ops.hpp 93.6% <100.0%> (+0.1%) ⬆️
test/git_issue_604.cpp 100.0% <100.0%> (ø)

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 14ba272...16b57d0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckormanyos

Copy link
Copy Markdown
Member

Hi @0x74h51N the CI run went green. There are two missed coverage lines. But we can fill in more tests later. This is better than the previous state. So I am going to merge to develop now.

Thank you very much for looking into this and improving the logic.

Cc: @jzmaddock and @mborland and @cosurgi

@ckormanyos
ckormanyos merged commit a116fb8 into boostorg:develop Aug 24, 2026
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cpp_bin_float fmod regression in boost version 1.90

2 participants